//package com.yunhe.authority.controller.base;
//
//import com.yunhe.authority.domain.base.Area;
//import com.yunhe.authority.service.base.AreaService;
//import com.yunhe.common.annotation.OperationRecord;
//import com.yunhe.common.constant.SystemConsts;
//import com.yunhe.common.model.PageParam;
//import com.yunhe.common.exception.ArgumentErrorException;
//import com.yunhe.common.exception.ObjectNotFoundException;
//import com.yunhe.common.exception.UniqueConstraintsException;
//import com.yunhe.common.model.DomainList;
//import com.yunhe.common.model.ResultObject;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiImplicitParam;
//import io.swagger.annotations.ApiImplicitParams;
//import io.swagger.annotations.ApiOperation;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Optional;
//
///**
// * 地区Controller
// * @author liuronglei
// * @desc 地区控制类定义
// */
//@Api(value = "area", description = "地区维护", tags = {"Base_Area"})
//@RestController
//@RequestMapping("/areas")
//public class AreaController {
//    @Autowired
//    private AreaService areaService;
//
//    /**
//     * 新增地区
//     * @param area 地区对象
//     */
//    @ApiOperation("新增地区")
//    @ApiImplicitParams({
//
//            @ApiImplicitParam(name = "parentId", value = "父地区ID", dataType = "long", paramType = "query")
//    })
//    @RequestMapping(method = RequestMethod.POST)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.ADD)
//    public ResponseEntity<ResultObject> post(
//            @RequestBody Area area,
//            @RequestParam("parentId") Optional<Long> parentId)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Area newArea = areaService.createArea(area, parentId.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(newArea), HttpStatus.OK);
//    }
//
//    /**
//     * 批量新增地区
//     * @param domainList 地区对象列表
//     */
//    @ApiOperation("批量新增地区")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/batch", method = RequestMethod.POST)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.ADD)
//    public ResponseEntity<ResultObject> batchPost(
//            @RequestBody DomainList<Area> domainList)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        Iterable<Area> newAreas = areaService.createArea(domainList.getList());
//        return new ResponseEntity<>(new ResultObject<>(newAreas), HttpStatus.OK);
//    }
//
//    /**
//     * 根据ID删除地区
//     * @param id id
//     */
//    @ApiOperation("根据ID删除地区")
//    @ApiImplicitParams({
//
//            @ApiImplicitParam(name = "id", value = "地区ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.DELETE)
//    public ResponseEntity<ResultObject> delete(
//            @PathVariable("id") Long id) {
//        areaService.deleteArea(id);
//        return new ResponseEntity<>(new ResultObject<>(null), HttpStatus.OK);
//    }
//
//    /**
//     * 根据地区代码删除地区
//     * @param code 地区代码
//     */
//    @ApiOperation("根据地区代码删除地区")
//    @ApiImplicitParams({
//
//            @ApiImplicitParam(name = "code", value = "地区代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/code/{code}", method = RequestMethod.DELETE)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.DELETE)
//    public ResponseEntity<ResultObject> deleteByCode(
//            @PathVariable("code") Long code) {
//        Long result = areaService.deleteAreaByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 根据地区编号删除地区
//     * @param name 地区编号
//     */
//    @ApiOperation("根据地区编号删除地区")
//    @ApiImplicitParams({
//
//            @ApiImplicitParam(name = "name", value = "地区编号", required = true, dataType = "string", paramType = "path")
//    })
//    @RequestMapping(value = "/name/{name}", method = RequestMethod.DELETE)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.DELETE)
//    public ResponseEntity<ResultObject> deleteByName(
//            @PathVariable("name") String name) {
//        Long result = areaService.deleteAreaByName(name);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 更新地区（更新全部字段）
//     * @param id ID
//     * @param area 地区对象
//     */
//    @ApiOperation("更新地区（更新全部字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PUT)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.EDIT)
//    public ResponseEntity<ResultObject> put(
//            @PathVariable("id") Long id,
//            @RequestBody Area area)
//            throws ArgumentErrorException, UniqueConstraintsException, ObjectNotFoundException {
//        area.setId(id);
//        Area newArea = areaService.updateArea(area);
//        return new ResponseEntity<>(new ResultObject<>(newArea), HttpStatus.OK);
//    }
//
//    /**
//     * 更新地区（更新指定字段）
//     * @param code 地区代码
//     * @param name 地区编号
//     * @param title 地区标题
//     * @param adminArea 行政区
//     */
//    @ApiOperation("更新地区（更新指定字段）")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "long", paramType = "path"),
//            @ApiImplicitParam(name = "code", value = "地区代码", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "name", value = "地区编号", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "title", value = "地区标题", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "adminArea", value = "行政区", dataType = "string", paramType = "query"),
//            @ApiImplicitParam(name = "parentId", value = "父地区ID", dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
//    @OperationRecord(menu = "地区管理", actionType = SystemConsts.ACTION.EDIT)
//    public ResponseEntity<ResultObject> patch(
//            @PathVariable("id") Long id,
//            @RequestParam("code") Optional<Long> code,
//            @RequestParam("name") Optional<String> name,
//            @RequestParam("title") Optional<String> title,
//            @RequestParam("adminArea") Optional<String> adminArea,
//            @RequestParam("parentId") Optional<Long> parentId)
//            throws ArgumentErrorException, ObjectNotFoundException, UniqueConstraintsException {
//        Area newArea = areaService.updateArea(id, code.orElse(null), name.orElse(null),
//                title.orElse(null), adminArea.orElse(null), parentId.orElse(null));
//        return new ResponseEntity<>(new ResultObject<>(newArea), HttpStatus.OK);
//    }
//
//    /**
//     * 根据ID获得地区对象
//     * @param id ID
//     */
//    @ApiOperation("根据ID获得地区对象")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "地区ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> get(
//            @PathVariable("id") Long id) {
//        Area area = areaService.findByAreaId(id);
//        return new ResponseEntity<>(new ResultObject<>(area), HttpStatus.OK);
//    }
//
//    /**
//     * 根据地区代码获得地区对象
//     * @param code 地区代码
//     */
//    @ApiOperation("根据地区代码获得地区对象")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "code", value = "地区代码", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(value = "/code/{code}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByCode(
//            @PathVariable("code") Long code) {
//        Area area = areaService.findByCode(code);
//        return new ResponseEntity<>(new ResultObject<>(area), HttpStatus.OK);
//    }
//
//    /**
//     * 根据地区编号获得地区对象
//     * @param name 地区编号
//     */
//    @ApiOperation("根据地区编号获得地区对象")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "name", value = "地区编号", required = true, dataType = "string", paramType = "path")
//    })
//    @RequestMapping(value = "/name/{name}", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByName(
//            @PathVariable("name") String name) {
//        Area area = areaService.findByName(name);
//        return new ResponseEntity<>(new ResultObject<>(area), HttpStatus.OK);
//    }
//
//    /**
//     * 根据条件获得地区列表
//     */
//    @ApiOperation("根据条件获得地区列表")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "systemId", value = "系统ID", required = true, dataType = "long", paramType = "path")
//    })
//    @RequestMapping(method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> search(
//            @ModelAttribute PageParam pageParam) {
//        Iterable<Area> results = areaService.findAreas(pageParam);
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//
//    /**
//     * 根据电站代码获得所属地区
//     * @param stationCode 电站代码
//     */
//    @ApiOperation("根据电站代码获得所属地区")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "stationCode", value = "电站代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/byStationCode", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByStationCode(
//            @RequestParam("stationCode") Long stationCode) {
//        Area result = areaService.findByStationCode(stationCode);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 根据单位代码获得所属地区
//     * @param firmCode 单位代码
//     */
//    @ApiOperation("根据单位代码获得所属地区")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "firmCode", value = "单位代码", required = true, dataType = "long", paramType = "query")
//    })
//    @RequestMapping(value = "/byFirmCode", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getByFirmCode(
//            @RequestParam("firmCode") Long firmCode) {
//        Area result = areaService.findFirmArea(firmCode);
//        return new ResponseEntity<>(new ResultObject<>(result), HttpStatus.OK);
//    }
//
//    /**
//     * 获得有单位关联的地区对象
//     */
//    @ApiOperation("获得有单位关联的地区对象")
//    @RequestMapping(value = "/withFirm", method = RequestMethod.GET)
//    public ResponseEntity<ResultObject> getFirmAreas(@PathVariable("systemId") Long systemId) {
//        Iterable<Area> results = areaService.findFirmAreas();
//        return new ResponseEntity<>(new ResultObject<>(results), HttpStatus.OK);
//    }
//}